#Test script of create account
require File.dirname(__FILE__)+'/../lib//testdata/testdata.rb'
require File.dirname(__FILE__)+'/../lib/elements/Accounts/element_Accounts.rb'
require File.dirname(__FILE__)+'/../lib/elements/Homepage/element_Homepage.rb'
require File.dirname(__FILE__)+'/../lib/reporting.rb'
require File.dirname(__FILE__)+'/../lib/std_lib.rb'
require 'watir'
require 'watir/testcase'
require 'win32ole'

class Create_Accounts < Watir::TestCase

    def test_setup
        OCRM_STD_LIB.ifstage_available

        #  $ie.bring_to_front
        filename  = File.basename(__FILE__).gsub(/\.rb/, "")
        #@@account_name="Tonytest"
        #@@search_in="Account Name"
        @@accountname = "Tonytest"+Time.now.strftime("%Y%m%d%H%M")
        begin
            $log=Reporting.new(File.dirname(__FILE__)+'/../doc/report/'"",filename)

        rescue
            puts $!
            puts $@
            $log.close unless $log.nil?
        end
    end
=begin
    def test_create_usaaccount
        Element::Tabs.accounts_tab.click
        Element::AccountHomePage.newaccount_button.click
        Element::CreateAccount.account_name_text_field.set(@@accountname + "_USA")
        Element::CreateAccount.operating_unit_name_select_list.set("Active.Com")
        Element::CreateAccount.operating_unit_id_select_list.set("86")
        Element::CreateAccount.market_1_select_list.select("Campgrounds")
        Element::CreateAccount.sub_market_1_select_list.set("Boat Licensing Departments")
        Element::CreateAccount.market_priority_1_select_list.set("A")
        Element::CreateAccount.market_status_1_select_list.set("Customer")
        Element::CreateAccount.bill_to_country_select_list.set("USA")
        Element::CreateAccount.bill_to_number_street_text_field.set("4570 Walnut Street")
        Element::CreateAccount.bill_to_address_2_text_field.set("1 Test")
        Element::CreateAccount.bill_to_city_text_field.set("Boulder")
        Element::CreateAccount.bill_to_county_text_field.set("Boulder")
        Element::CreateAccount.bill_to_state_select_list.set("CO")
        Element::CreateAccount.bill_to_zip_text_field.set("80301")
        Element::CreateAccount.save_button.click
    end
=end
    def test_create_canaccount
        Element::Tabs.accounts_tab.click
        Element::AccountHomePage.newaccount_button.click
        Element::CreateAccount.account_name_text_field.set(@@accountname + "_CAN")
        Element::CreateAccount.operating_unit_name_select_list.set("Canada Operating Unit")
        Element::CreateAccount.operating_unit_id_select_list.set("97")
        Element::CreateAccount.market_1_select_list.select("Campgrounds")
        Element::CreateAccount.sub_market_1_select_list.set("Boat Licensing Departments")
        Element::CreateAccount.market_priority_1_select_list.set("A")
        Element::CreateAccount.market_status_1_select_list.set("Customer")
        ai=WIN32OLE.new("AutoItX3.Control")
        ai.WinActivate("Accounts - Oracle CRM On Demand")
        ai.MouseClickDrag("right",1671,366,1671,550)
        ai.MouseClick("right",613,550)
        ai.MouseClickDrag("right",612,908,613,641)
        ai.MouseClick("right",468,651)
        #        There is something wrong with the country selection, then I use autoit to do the country selection.
        #        Element::CreateAccount.bill_to_country_select_list.set("Canada")
        Element::CreateAccount.bill_to_number_street_text_field.set("111 Robson ST")
        Element::CreateAccount.bill_to_address_2_text_field.set("1 Test")
        Element::CreateAccount.bill_to_city_text_field.set("Vancouver")
        Element::CreateAccount.bill_to_province_text_field.set("British Columbia")
        #Bugs about Select countries
        Element::CreateAccount.bill_to_zip_text_field.set("V6G3H7")
        Element::CreateAccount.save_button.click
    end
=begin
    def test_quick_create_usaaccount
        # Create account of Active.Com
        Element::_Create.quick_create_account_link.click
        sleep 5
        $ie = Watir::IE.attach(:title,/Accounts/)
        Element::QuickCreateAccount.account_name_text_field.set(@@accountname + "_USA")
        Element::QuickCreateAccount.operating_unit_name_select_list.set("Active.Com")
        Element::QuickCreateAccount.operating_unit_id_select_list.set("86")
        Element::QuickCreateAccount.market_1_select_list.select("Campgrounds")
        Element::QuickCreateAccount.sub_market_1_select_list.set("Boat Licensing Departments")
        Element::QuickCreateAccount.market_priority_1_select_list.set("A")
        Element::QuickCreateAccount.market_status_1_select_list.set("Customer")
        Element::QuickCreateAccount.bill_to_country_select_list.set("USA")
        Element::QuickCreateAccount.bill_to_number_street_text_field.set("4570 Walnut Street")
        Element::QuickCreateAccount.bill_to_address_2_text_field.set("1 Test")
        Element::QuickCreateAccount.bill_to_city_text_field.set("Boulder")
        Element::QuickCreateAccount.bill_to_county_text_field.set("Boulder")
        Element::QuickCreateAccount.bill_to_state_select_list.set("CO")
        Element::QuickCreateAccount.bill_to_zip_text_field.set("80301")
        Element::QuickCreateAccount.save_button.click
    end
=end
=begin
    def test_quick_create_canaccount
        #Quick Creat account of CAN
        Element::Quick_Create.quick_create_account_link.click
        sleep 5
        #If there is no ie windows before the testcase was run, watir could not focus the pop up window
        #How to solve that?
        #Now my method is make sure there is at least one ie window before running the case,even blank is ok.
        $ie = Watir::IE.attach(:title,/Accounts/)
        $ie.maximize
        $ie.bring_to_front
        #$ie.set_slow_speed
        # Make sure the page was load completed.
        #$ie.refresh
        #sleep 10

        Element::QuickCreateAccount.account_name_text_field.set(@@accountname + "_CAN")
        Element::QuickCreateAccount.operating_unit_name_select_list.set("Canada Operating Unit")
        Element::QuickCreateAccount.operating_unit_id_select_list.set("97")
        Element::QuickCreateAccount.market_1_select_list.select("Campgrounds")
        Element::QuickCreateAccount.sub_market_1_select_list.set("Boat Licensing Departments")
        Element::QuickCreateAccount.market_priority_1_select_list.set("A")
        Element::QuickCreateAccount.market_status_1_select_list.set("Customer")
        ai=WIN32OLE.new("AutoItX3.Control")
        ai.WinActivate("Accounts - Oracle CRM On Demand")
        ai.MouseClickDrag("right",1668,320,1668,524)
        ai.MouseClick("right",485,520)
        ai.MouseClickDrag("right",485,878,485,610)
        ai.MouseClick("right",330,620)
        #        There is something wrong with the country selection, then I use autoit to do the country selection.
        #        Element::QuickCreateAccount.bill_to_country_select_list.set("Canada")
        Element::QuickCreateAccount.bill_to_number_street_text_field.set("111 Robson ST")
        Element::QuickCreateAccount.bill_to_address_2_text_field.set("1 Test")
        Element::QuickCreateAccount.bill_to_city_text_field.set("Vancouver")
        Element::QuickCreateAccount.bill_to_province_text_field.set("British Columbia")
        #Bugs about Select countries
        Element::QuickCreateAccount.bill_to_zip_text_field.set("V6G3H7")
        Element::QuickCreateAccount.save_button.click
    end
=end



    def test_reset

    end

    def test_tear_down
        @@for = nil
        @@search_in = nil
    end
end


class NewAccounts < Watir::TestCase
    def test_setup
    end

    def test_tear_down
        $log.close unless $log.nil?
    end
end